import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/pages/lf_verify/lf_verify_camera_confirm/lf_verify_camera_confirm_logic.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/widgets/custom_cache_image.dart';
import 'package:video_player/video_player.dart';

import '../../../res/lf_color.dart';
import '../../../res/lf_fonts.dart';
import '../../../res/lf_text_style.dart';
import '../../../res/strings/lf_strings.dart';
import '../../../widgets/lf_app_bar.dart';
import '../../../widgets/lf_button.dart';
import '../lf_verify_camera/lf_verify_camera_logic.dart';

class LfVerifyCameraConfirmPage extends StatefulWidget {
  const LfVerifyCameraConfirmPage({super.key});

  @override
  State<LfVerifyCameraConfirmPage> createState() =>
      _LfVerifyCameraConfirmPageState();
}

class _LfVerifyCameraConfirmPageState extends State<LfVerifyCameraConfirmPage> {
  final logic = Get.put(LfVerifyCameraConfirmLogic());

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: lfAppBar(
              title: strVerifyByVideoOrID.tr,
              leadingCallback: () {
                toVerifyCamera(gesture: logic.gesture, needOff: true);
              }),
          body: Padding(
            padding: EdgeInsets.symmetric(horizontal: 10.w),
            child: GetBuilder<LfVerifyCameraConfirmLogic>(
              builder: (logic) {
                return CustomScrollView(
                  slivers: [
                    Row(
                      children: [
                        Expanded(child: LayoutBuilder(
                          builder: (context, constants) {
                            return CustomCacheImage(
                              imageUrl: logic.gesture.verticalPic,
                              radius: 10.r,
                              width: constants.maxWidth,
                              height: constants.maxWidth * 800.0 / 686,
                            );
                          },
                        )),
                        10.w.sbw,
                        Expanded(child: LayoutBuilder(
                          builder: (context, constants) {
                            return logic.controller.value.isInitialized
                                ? ClipRRect(
                                    borderRadius: 10.r.radius,
                                    child: SizedBox(
                                        width: constants.maxWidth,
                                        height:
                                            constants.maxWidth * 800.0 / 686,
                                        child: AspectRatio(
                                          aspectRatio: logic
                                              .controller.value.aspectRatio,
                                          child: VideoPlayer(logic.controller),
                                        )),
                                  )
                                : Container(
                                    width: constants.maxWidth,
                                    height: constants.maxWidth * 800.0 / 686,
                                    decoration: BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: 10.r.radius),
                                  );
                          },
                        )),
                      ],
                    ).sliverBox,
                    40.h.sliverBox,
                    LfButton(
                      text: strSubmit.tr.toUpperCase(),
                      onPress: () {
                        logic.verifyVideo();
                      },
                      enabled: true,
                    ).sliverBox,
                    30.h.sliverBox,
                    Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 20),
                      child: InkWell(
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 12.h),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: 40.r.radius,
                              border:
                                  Border.all(color: colorFEFEFE, width: 2.r)),
                          child: Text(
                            strRetry.tr,
                            style: lfTextStyle(
                                sp: 17.sp,
                                fontFamily: fontBold,),
                          ),
                        ),
                        onTap: () {
                          toVerifyCamera(gesture: logic.gesture, needOff: true);
                        },
                      ),
                    ).sliverBox
                  ],
                );
              },
            ),
          ),
        ),
        onWillPop: () async {
          toVerifyCamera(gesture: logic.gesture, needOff: true);
          return false;
        });
  }
}
